package com.steven.collection;

import java.util.Iterator;
import java.util.*;

public class TreeSetDemo {
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TreeSet <Student> ts = new TreeSet <Student>(new MyComparator());
		ts.add(new Student("11",33));

		ts.add(new Student("lisi02",22));
		ts.add(new Student("lisi007",20));
		ts.add(new Student("lisi09",19));
		ts.add(new Student("lisi08",19));
		ts.add(new Student("lisi007",20));
		ts.add(new Student("lisi01",40));

		Iterator it = ts.iterator();
		while(it.hasNext())
		{
			Student stu = (Student)it.next();
			System.out.println(stu.name +"..."+stu.age);
		}
		
		System.out.println("-----------------------------");
		 

			ArrayList al = new ArrayList();

			String str = "90 -7 0 18 2 45 4";

			String[] arr = str.split(" ");

			TreeSet ts1 = new TreeSet();

			for(int x=0; x<arr.length; x++)
			{
				//ts.add(new Integer(arr[x]));
				ts1.add(Integer.parseInt(arr[x]));//
			}

			System.out.println(ts1);
		 

	}

}

class Student implements Comparable<Student>{
	String name;
	int age ;
	Student(){
		
	}
	Student(String name,int age ){
		this.name=name;
		this.age=age;
		
	}
	@Override
	public int compareTo(Student o) {
		
		 if(this.age!=o.age)
			 return this.age-o.age;
		  
		return this.name.compareTo(o.name);
	}
	
	
}
